#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        bool bitmap[256] = { false };
        int head = 0, tail = 0, maxLen = 0, size = s.length();

        for (int i = 0; i < size; ++i) {
            if (bitmap[s[i]]) {
                maxLen = (maxLen < (tail - head)) ? (tail - head) : maxLen;
                for (; s[head] != s[i]; ++head) {
                  bitmap[s[head]] = false;
                }
                ++head;
                ++tail;
            } else {
                ++tail;
                bitmap[s[i]] = true;
            }
        }
        maxLen = (maxLen < (size - head)) ? (size - head) : maxLen;
        return maxLen;
    }
};

int main()
{
  string s = "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmco";
  Solution solution;

  cout<<s<<endl;
  cout<<"longest substring w/o repeated characater: "
      <<solution.lengthOfLongestSubstring(s)<<endl;

  return 0;
}
